/**
 *
 * @author yuripadua
 */
package novoRIP.servidor;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

public class serverMulthreadTCP extends Thread {

    private ServerSocket welcomeSocket;

    public serverMulthreadTCP(int porta) throws IOException {
        welcomeSocket = new ServerSocket(porta);
    }

    //public void run(Socket acceptSocket) throws IOException {
    public void run() {
        Socket connectionSocket = null;

        String clientSentence = "";
        String capitalizedSentence = "";

        ObjectInputStream inFromClient = null;
        ObjectOutputStream outToClient = null;

        while (true) {
            try {
                connectionSocket = welcomeSocket.accept();
                inFromClient = new ObjectInputStream(connectionSocket.getInputStream());
                outToClient = new ObjectOutputStream(connectionSocket.getOutputStream());


                clientSentence = (String) inFromClient.readObject();
                //clientSentence = inFromClient.readLine();

                teste aux = (teste) inFromClient.readObject();
                System.out.println("Server: " + aux.getAux());
                capitalizedSentence = clientSentence.toUpperCase() + '\n';
                aux.setAux(2);
                outToClient.writeObject(aux);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(serverMulthreadTCP.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(serverMulthreadTCP.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
